package com.emip.servlet.baseinfo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emip.bean.AlarmConfigBean;
import com.emip.config.SysParams;
import com.emip.pojo.Table;
import com.emip.service.AlarmConfigService;
import com.emip.util.TableFormat;

@Controller
@RequestMapping(value="/base/alarmConfig")
public class AlarmConfigAction {

	@Autowired
	AlarmConfigService alarmConfigService;
	
	@RequestMapping(value="/management")
	public String index() {		
		return "/baseInfo/AlarmConfigManagement";
	}
	
	@RequestMapping(value="/getAllAlarmConfigs")
	public @ResponseBody Table<AlarmConfigBean> getAllAlarmConfigs() {
		List<AlarmConfigBean> result = alarmConfigService.getAll();
		int records = result.size();
		int totalPages = records / SysParams.gridDefinedRowNumber + 1;
		return new TableFormat<AlarmConfigBean>().formTable(totalPages, 1, records, result);

	}
	
	@RequestMapping(value="/getAlarmConfigByID",method=RequestMethod.POST, headers="Accept=application/json")
	public @ResponseBody AlarmConfigBean getAlarmConfigByID(@RequestParam("eid") int eid) {
		return alarmConfigService.getAlarmConfigByID(eid);
	}
	
	@RequestMapping(value="/addAlarmConfig",method=RequestMethod.POST)
	public @ResponseBody AlarmConfigBean addAlarmConfig(@RequestParam("alarmID")  String alarmID, @RequestParam("alarmName") String alarmName,
			@RequestParam("sendTimes") int sendTimes) {
		return alarmConfigService.addAlarmConfig(alarmID, alarmName, sendTimes);
	}
	
	@RequestMapping(value="/updateAlarmConfig",method=RequestMethod.POST)
	public @ResponseBody AlarmConfigBean updateAlarmConfig(@RequestParam("id") int id, @RequestParam("alarmID")  String alarmID, 
			@RequestParam("alarmName") String alarmName, @RequestParam("sendTimes") int sendTimes) {
		return alarmConfigService.updateAlarmConfig(id, alarmID, alarmName, sendTimes);		
	}
	
	@RequestMapping(value="/deleteAlarmConfig",method=RequestMethod.POST)
	public @ResponseBody String deleteAlarmConfig(@RequestParam("eID") int id) {
		alarmConfigService.deleteAlarmConfig(id);
		return "success";
	}
	
	@RequestMapping(value="/getAllAlarmConfigsObj")
	public @ResponseBody List<AlarmConfigBean> getAllAlarmConfigsObj() {
		return alarmConfigService.getAll();
	}
}
